package com.example.sample.controller;

import com.example.sample.Infrastructure.Repository.IStudentRepository;
import com.example.sample.domain.Entity.Student;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static org.springframework.web.bind.annotation.RequestMethod.GET;

@RestController()
@RequestMapping("/hello")
public class HellowController {

    //日志组件
    private Logger log = LoggerFactory.getLogger(HellowController.class);

    @Autowired
    private IStudentRepository studentRepository;

    @RequestMapping("/hello")
    public String index() {
        int c = 10/0;

        log.info("测试日志！");
        return "Hello World";
    }

    @GetMapping("/student")
    public List<Student> GetStudentList() {
        List<Student> all = studentRepository.findAll();
        return  all;
    }

    @GetMapping("/student/{id}")
    public Student GetStudentById(@PathVariable String id) {
        Student student = studentRepository.getOne(id);
        return  student;
    }
}

